package com.wang.designpattern.responsibilitychain;

import com.wang.designpattern.responsibilitychain.domain.AttendanceClockDO;
import org.springframework.beans.BeanUtils;

import java.util.Map;
import java.util.Objects;

/**
 * 迟到处理类
 */
public class PmLateAttendanceHandler extends AttendanceHandler{
    public PmLateAttendanceHandler(String name) {
        super(name);
    }

    @Override
    public void processRequest(Map<String, AttendanceClockDO> clockResultDataMap, AttendanceClockDO attendanceClockDO) {

        AttendanceClockDO clockResultData = clockResultDataMap.get(AttendanceConstant.ExceptionType.LATE.getExceptionType());
        if (Objects.isNull(clockResultData)) {
            clockResultData = new AttendanceClockDO();
            BeanUtils.copyProperties(attendanceClockDO, clockResultData);
        }

        //1、0 < “下午实际上班打卡时间” - “下午上班时间” <= 30分钟
        if (DateUtils.calcTime(attendanceClockDO.getClockDate(), attendanceClockDO.getPmStartTime(),
                attendanceClockDO.getPmSetStartTime()) > 0 &&
                DateUtils.calcTime(attendanceClockDO.getClockDate(), attendanceClockDO.getPmStartTime(),
                        attendanceClockDO.getPmSetStartTime()) <= 30) {
            clockResultData.setExceptionType(AttendanceConstant.ExceptionType.LATE.getExceptionType());
            clockResultData.setExceptionCount(clockResultData.getExceptionCount()+1);
            clockResultData.setExceptionUnit("T");
            clockResultDataMap.put(AttendanceConstant.ExceptionType.LATE.getExceptionType(), clockResultData);
            System.out.println(this.name + " 进行处理----------");
        }
        handler.processRequest(clockResultDataMap, attendanceClockDO);
    }
}
